package com.boot.mybatis.repository;

import com.boot.commons.option.SexEnum;
import com.boot.commons.vo.User;
import com.boot.mybatis.handler.SexEnumHandler;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {


    @Select("SELECT id,username,password ,sex,nick_name FROM user")
    @Results({
            @Result(property = "sex", column = "sex", javaType = SexEnum.class, typeHandler =
                    SexEnumHandler.class),
            @Result(property = "nickName", column = "nick_name")
    })
    List<User> getAll();


    @Insert("INSERT INTO user(username,password,sex,nick_name) VALUES(#{userName}, #{password}, #{sex.code}," +
            "#{nickName})")
    boolean insert(User user);

    @Update("update user set username=#{userName},password=#{password},sex=#{sex.code},nick_name=#{nickName} where " +
            "id=7")
    boolean update(User user);


}
